package interview.eventSystem;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by richard on 6/3/14.
 */
public class UpperServer implements Runnable{//implement runnable for simulate
    private int serverId=0;
    private Container container;

    public UpperServer(int serverId) {
        this.serverId = serverId;
    }

    public Container getContainer() {
        return container;
    }

    public void setContainer(Container container) {
        this.container = container;
    }

    public Event generateEvent(){
        Event event = new Event();
        event.setMessage("Generated by : Server" +serverId );
        System.out.println("generate a event from server:" + serverId + "with eventId " + event.getId());
        return event;
    }

    @Override
    public void run() {
        try {
        while(!Thread.currentThread().isInterrupted()) {

            Thread.sleep(1000);
            getContainer().addEvent(generateEvent());
        }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

    }
}
